package com.formulas.certification.oauth.extension;

import cn.hutool.core.util.StrUtil;
import com.formulas.certification.CertificationConstants;
import com.formulas.certification.domain.oauth.gateway.OauthClientDetailsGateway;
import com.formulas.certification.domain.oauth.model.OauthClientDetailsEntity;
import com.formulas.certification.oauth.extensionpoint.OauthClientDetailsCheckExtPt;
import com.formulas.component.exception.Assert;
import com.formulas.component.extension.Extension;
import jakarta.annotation.Resource;

/**
 * @author yiwannuofulasi
 * @date 2023/6/14 18:45
 */
@Extension(bizId = CertificationConstants.BIZ_1)
public class OauthClientDetailsCheckExt implements OauthClientDetailsCheckExtPt {

    @Resource
    private OauthClientDetailsGateway oauthClientDetailsGateway;

    @Override
    public OauthClientDetailsEntity oauthClientDetailsCheck(String clientId) {
        if (StrUtil.isBlankOrUndefined(clientId)){
            Assert.requestParams("客户端唯一标识#clientId="+clientId);
        }
        OauthClientDetailsEntity oauthClientDetailsEntity = oauthClientDetailsGateway.oauthClientDetailsCheck(clientId);
        if (null==oauthClientDetailsEntity){
            Assert.noDataFound("根据客户端唯一标识查询数据库没有发现对应的客户端应用记录信息#clientId="+clientId);
        }
        return oauthClientDetailsEntity;
    }
}
